package es.cea.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/Calculadora")
public class CalculadoraServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	private double dvalor1;
	private double dvalor2;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String valor1 = request.getParameter("valor1");
		String valor2 = request.getParameter("valor2");
		String operador = request.getParameter("operador");
		
		dvalor1 = Double.parseDouble(valor1);
		dvalor2 = Double.parseDouble(valor2);
		
		Calculadora calculadora = new Calculadora(dvalor1, dvalor2);
		
		PrintWriter writer = response.getWriter();
		writer.println("Respuesta\n");
		writer.println("valor1: " + valor1 +"\n");
		writer.println("valor2: " + valor2 + "\n");
		writer.println("operador: " + operador + "\n");
		writer.println("Resultado: " + calculadora.opera(operador) + "\n");
		
		
		writer.println("FIN PROCESO");
		writer.close();
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
